#! /usr/bin/env python
"""
    Adelide - A virtual media bookshelf.
    Copyright (C) Niklas Johansson jonikl@ituniv.se

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""

import sys
sys.path.append('../')
import os
from adelib import media

def print_help():
    print "Adelide Importer Ver. 0.1"
    print "Niklas Johansson (C) 2008"
    print "--------------------------------"
    print "Use: ./importer [commands] [file]"
    print "Commands:"
    print "-h - prints this help message"

if __name__ == "__main__":
    if len(sys.argv) > 1:
        for arg in sys.argv[1:]:
            if arg == "-h":
                print_help()
                quit()
            else:
                if os.path.isfile(arg):
                    f=open(arg, 'r')
                    new_media = None
                    line = f.readline()
                    if line == "<media>\n":
                        print "Media found!"
                        new_media = media.Media()
                        for line in f.readlines():
                            if line[0:6] == "<type>":
                                print line[6:len(line)-8]
                            elif line[0:7] == "<title>":
                                print line[7:len(line)-9]
                            elif line[0:6] == "<year>":
                                print line[6:len(line)-8]
                            elif line[0:8] == "<format>":
                                print line[8:len(line)-10]
                            elif line[0:5] == "<ean>":
                                print line[5:len(line)-7]
                    else:
                        print "File does not comply to standard. See Example."
                else:
                    print "File does not exist."
    else:
        print_help()
